<?php
include("header.php");
$pageTitle = "AdminCP | Synchronize user posts";
if($_SESSION['user_level'] != 1 )
{
	header("location: redirect.php");
}
else
 {
if($_SERVER['REQUEST_METHOD'] != 'GET')
{
echo 'This file cannot be called directly.';}
else
{

$result = $db->query("SELECT * FROM ".$table_prefix."users"); 
if (!$result)
{echo "Error selecting database!";}
   else
  {
   while($row = mysql_fetch_assoc($result))
   {
   $user_posts = $db->query("SELECT * FROM ".$table_prefix."posts WHERE post_by = ".$row['user_id']."");
   $row2 = mysql_num_rows($user_posts);
   if ($row2 != $row['user_posts']) {
   echo "<b>".$row['user_name']."</b> posts: ".$row['user_posts']."| Synch posts= ".$row2."<br > ";
   if($row2 != $row['user_posts'])
   {$result2 = $db->query("UPDATE ".$table_prefix."users SET user_posts = ".$row2." WHERE user_id = ".$row['user_id']."");}
   }
   if ($row['is_banned'] == 1)
   {$checkban = $db->query("SELECT ban_userid FROM ".$table_prefix."banlist WHERE ban_userid= $row[user_id] LIMIT 1");
   if (mysql_num_rows($checkban)<=0)
   {$synch_ban = $db->query("UPDATE ".$table_prefix."users SET is_banned=0 WHERE user_id=$row[user_id] LIMIT 1");}
   echo "<br>Synch ban: $row[user_name] - remove ban";
   }

   }
echo "<br /><div align='center'><b>Result: All users synchronized!</b><br><br><a href='javascript: history.go(-1) '>Back to ACP</a></div><br>";  
 }
}
}
$pageContents = ob_get_contents (); // Get all the page's HTML into a string
ob_end_clean (); // Wipe the buffer 
echo str_replace ('<!--TITLE-->', $pageTitle, $pageContents);  	
 ?>